package com.yc.damai.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.yc.damai.bean.Result;
import com.yc.damai.bean.User;
import com.yc.damai.biz.BizException;
import com.yc.damai.biz.CartBiz;

@WebServlet("/addCart.s")
public class AddCartServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private CartBiz biz = new CartBiz();

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String pid = request.getParameter("pid");
		String count = request.getParameter("count");
		User user = (User) request.getSession().getAttribute("loginedUser");
		biz.addCart(user.getUid(), pid, count);
		String json = new Gson().toJson(new Result(1, "添加购物车成功"));
		response.getWriter().append(json);
	}

}
